package main

import ("github.com/garyburd/redigo/redis"
        "fmt"
	"reflect"
)


func main()  {
	conn,err := redis.Dial("tcp","192.168.1.203:6379")
	if err != nil {
		fmt.Println("connect redis error :",err)
		return
	}
	defer conn.Close()
	_, err = conn.Do("SET", "name", "wd")
	if err != nil {
		fmt.Println("redis set error:", err)
	}
	_, err = conn.Do("expire", "name", 10) //10秒过期
	if err != nil {
		fmt.Println("set expire error: ", err)
		return
	}
	name, err := redis.String(conn.Do("GET", "name"))
	if err != nil {
		fmt.Println("redis get error:", err)
	} else {
		fmt.Printf("Got name: %s \n", name)
	}



    //批量设置 批量获取
	_, err = conn.Do("MSET", "name", "wd","age",22)
	    if err != nil {
		fmt.Println("redis mset error:", err)
	}
	res, err := redis.Strings(conn.Do("MGET", "name","age"))
	    if err != nil {
		fmt.Println("redis get error:", err)
	} else {
		res_type := reflect.TypeOf(res)
		fmt.Printf("res type : %s \n", res_type)
		fmt.Printf("MGET name: %s \n", res)
		fmt.Println(len(res))
	}//结果：//res type : []string
	//MGET name: [wd 22]
	//2


}

